package es.deusto.tralala.rmi.client.remote;

import es.deusto.tralala.rmi.server.ITralalaFacade;

public class RMIServiceLocator {
	/** 
	 * The Cache - Limitation: one server at a time
	 * Proposed improvement: list of services
	 */
	private ITralalaFacade service;

    /** Creates a new instance of RMIServiceLocator */
    public RMIServiceLocator() {
    }

    public void setService(String ip, String port, String serviceName) {    
    	// Add your code to get the TARGET reference HERE (codigo sacado client.java practica RMI)
		try {
			String name = "//" + ip + ":" + port + "/" + serviceName;
			service = (ITralalaFacade) java.rmi.Naming.lookup(name);
		} catch (Exception e) {
			System.err.println("- Exception running the client: " + e.getMessage());
			e.printStackTrace();
		}
    }
    
    public ITralalaFacade getService() {    	
    	// Add your code to return the TARGET reference HERE
    	return service;
    }
}
